{include file="public/layout" /}

<body class="nav-more">
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body " style="overflow-x: scroll">
            <div class="layui-table-box">
                <div class="layui-table-body layui-table-main right-oper" style="margin: 0;">
                    <table id="table1" class="layui-table" lay-filter="table1"></table>
                    <!-- 操作列 -->
                    <script type="text/html" id="oper-col">
                        <a class="layui-btn btn-edit" lay-event="select"  data-id="{{d.id}}" data-name="{{d.name}}" >选择</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var json_arctype_list = {$list|json_encode};
    var callback = "{$func}";
    layui.config({
        base: '__SKIN__/', //静态资源所在路径
        version:'{$version}'
    }).extend({
        index: 'lib/index', //主入口模块
        treetable: 'treetable-lay/treetable'//树形栏目
    }).use([ 'table', 'treetable','index','layer'], function () {
        var $ = layui.$
            ,form = layui.form
            ,treetable = layui.treetable
            ,table = layui.table;


        // 渲染表格
        var renderTable = function () {
            layer.load(2);
            treetable.render({
                treeColIndex: 1,
                treeSpid: 0,    //为顶级栏目时的parent_id值
                treeIdName: 'id',
                treePidName: 'parent_id',
                treeDefaultClose: false,
                treeLinkage: false,
                elem: '#table1',
//                url: layui.setter.base +'json/ey_json/arctype.js?v={$version}',
                page: false,
                data:json_arctype_list,
                cols: [[
                    {field: 'id', title: 'ID', width: 80}
                    ,{field: 'name', title: '<a href="javascript:;" class="arctype-btn-expand"  id="btn-expand" style="display: none;"></a><a href="javascript:;" class="arctype-btn-fold" id="btn-fold"></a>栏目名称', minWidth: 300}
                    ,{field:'oper-col', title: '操作', width: 135,align:'center',templet: '#oper-col'}
                ]],
                done: function () {
                    layer.closeAll('loading');
                }
            });
        };

        renderTable();

        $('#btn-expand').click(function () {
            $('#btn-expand').hide();
            $('#btn-fold').show();
            treetable.expandAll('#table1');
        });

        $('#btn-fold').click(function () {
            $('#btn-expand').show();
            $('#btn-fold').hide();
            treetable.foldAll('#table1');
        });

        //监听工具条
        table.on('tool(table1)', function (obj) {
            var layEvent = obj.event;
            var data = obj.data;
            if (layEvent === 'select') {
                var fileurl_tmp = [];
                fileurl_tmp['id'] = data.id;
                fileurl_tmp['level'] = data.level;
                fileurl_tmp['parent_id'] = data.parent_id;
                fileurl_tmp['name'] = data.name;
                eval('window.parent.'+callback+'(fileurl_tmp)');
            }
        });
        //栏目更多弹出按钮触发事件
        $(document).off('mousedown','.layui-table-grid-down').
        on('mousedown','.layui-table-grid-down',function (event) {
            table._tableTrCurrr = $(this).closest('td');
        });
        $(document).off('click','.layui-table-tips-main [lay-event]').
        on('click','.layui-table-tips-main [lay-event]',function (event) {
            var elem = $(this);
            var tableTrCurrr =  table._tableTrCurrr;
            if(!tableTrCurrr){
                return;
            }
            var layerIndex = elem.closest('.layui-table-tips').attr('times');
            layer.close(layerIndex);
            table._tableTrCurrr.find('[lay-event="' + elem.attr('lay-event') + '"]').first().click();
        });

    });

</script>
{include file="public/footer" /}

